{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "x = raw_input('输入命令'.decode('utf-8'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "UnicodeDecodeError",
     "evalue": "'utf8' codec can't decode byte 0xe5 in position 0: unexpected end of data",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mUnicodeDecodeError\u001b[0m                        Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-10-0682fc89cc9b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mf4\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'liststructure'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mliststructure\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mf4\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[0mliststructure\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'utf-8'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mD:\\Anaconda\\lib\\encodings\\utf_8.pyc\u001b[0m in \u001b[0;36mdecode\u001b[1;34m(input, errors)\u001b[0m\n\u001b[0;32m     14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     15\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdecode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'strict'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m     \u001b[1;32mreturn\u001b[0m \u001b[0mcodecs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mutf_8_decode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     17\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     18\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mIncrementalEncoder\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcodecs\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mIncrementalEncoder\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mUnicodeDecodeError\u001b[0m: 'utf8' codec can't decode byte 0xe5 in position 0: unexpected end of data"
     ]
    }
   ],
   "source": [
    "f4=open('liststructure')\n",
    "liststructure=f4.read()\n",
    "print liststructure[0].decode('utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from pyswip import Prolog\n",
    "\n",
    "#注意Pathlist的元素需要是字符串\n",
    "def Path():\n",
    "#Pathlist记录起点和终点的数组，Path路径，Pathlist结构[“起点x”，“起点y”，“起点z”，“起点名称”，“终点x”，“终点y”，“终点z”，“终点名称”]\n",
    "    f1=open('pathlist.txt','r')\n",
    "    path=[]\n",
    "    Pathlist[]\n",
    "    prolog = Prolog() \n",
    "    prolog.consult('point_polygon.pl') \n",
    "    prolog.consult('area_5F.pl') \n",
    "    prolog.consult('node_5F.pl')\n",
    "    prolog.consult('a_star_3.0.pl') \n",
    "    prolog.consult('directly_link.pl') \n",
    "    qqq = \"path_plan(\" + Pathlist[0] + \",\" + Pathlist[1]+ \",\" + Pathlist[2]+ \",\" + Pathlist[7] + \",Coorlist)\"\n",
    "\n",
    "    for result in prolog.query(qqq): \n",
    "        path = result[\"Coorlist\"] \n",
    "    print path\n",
    "Path(Pathlist,path)\n",
    "if __name__==\"__main__\":\n",
    "    Path()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['565', '2', '1', 'a604']\n",
      "[600, 112, 420, 717.3, 237, 420, 717.3, 797, 420, 717.3, 1376, 420, 717.3, 5662.3, 420, 1467.3, 6448.5, 420, 1925.3, 6564, 420, 3930.3, 6449, 420, 4170.3, 6449, 420, 4585.3, 6449, 420, 4825.3, 6449, 420, 8255.3, 6459, 420, 8492.3, 6459, 420, 9162.3, 6459, 420, 12199, 7426.7, 420, 12331.9, 7492, 495, 12809.6, 7714.7, 495, 12845.8, 7847.5, 495, 11460.6, 10607.7, 495]\n"
     ]
    }
   ],
   "source": [
    "from pyswip import Prolog\n",
    "f1=open('pathlist.txt','r')\n",
    "Pathlist=[]\n",
    "path=[]\n",
    "#Pathlist[]=f1.readlines()\n",
    "#Pathlist[0]=Pathlist[0].replace(\"\\t,\")\n",
    "#print Pathlist\n",
    "Pathlist=f1.readlines()\n",
    "for i in range(len(Pathlist)):\n",
    "    Pathlist[i]=str(Pathlist[i].replace(\"\\n\",\"\"))\n",
    "Pathlist.append(\"a604\")\n",
    "\n",
    "prolog = Prolog() \n",
    "prolog.consult('point_polygon.pl') \n",
    "prolog.consult('area_5F.pl') \n",
    "prolog.consult('node_5F.pl')\n",
    "prolog.consult('a_star_3.0.pl') \n",
    "prolog.consult('directly_link.pl') \n",
    "qqq = \"path_plan(\" + Pathlist[0] + \",\" + Pathlist[1]+ \",\" + Pathlist[2]+ \",\" + Pathlist[3] + \",Coorlist)\"\n",
    "for result in prolog.query(qqq): \n",
    "    path = result[\"Coorlist\"]    \n",
    "print path    \n",
    "#print Pathlist\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
